package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.UserInfo;
import com.cskaoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("list")
    public BaseRespVo userList(UserInfo userInfo) {
        List<User> users = userService.query(userInfo);
        return BaseRespVo.ok(users);
    }

    @GetMapping("add")
    public BaseRespVo add1(User user) {
        userService.add(user);
        return BaseRespVo.ok(null);
    }

    @PostMapping("add")
    public BaseRespVo add2(@RequestBody User user) {

        userService.add(user);
        return BaseRespVo.ok(null);
    }
}
